#!/usr/bin/perl -w
use strict;
use Getopt::Long;

#88888888888888888888888888888888888888888888888888888888888888888888888888888888

#       Usage

#88888888888888888888888888888888888888888888888888888888888888888888888888888888

my $usage = <<'USAGE';

USAGE:

    matrix_to_short_names.pl
        --name_map  name_map.file
USAGE
			    
							    
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
						    
#       Get options
								    
#88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
# mandatory
my $name_map;										    
								    
# optional parameters
my  $help;
GetOptions(
            'name_map=s'           => \$name_map,
            'help'                 => \$help);
																						    
    die $usage if ($help);
    die $usage unless ($name_map);

    my $line = <>;
    my $line_cnt = 0;
    open F_MAP, ">$name_map" or 
	    die "Error\n\tCould not open $name_map\n";
    print $line;
    while (<>)
    {
	my ($name) = split /\s/;
	my $mname =  sprintf "XYZX%05d", $line_cnt++;
	print F_MAP "$mname\t$name\n";
	s/$name/$mname/;
	print;
    }
